window.g_Audio = new (class CAudioManager {
    constructor() {
        this.m_AudioList = [];
    }
    add(audio) {
        if (!audio) return;
        this.m_AudioList.push(audio);
    }
    remove(audio) {
        let index = this.m_AudioList.indexOf(audio);
        if (index != -1) this.m_AudioList.splice(index, 1);
    }

    playMusic() {
        cc.loader.loadRes("audio/bgm", cc.AudioClip, (err, item) => {
            if (err) {
                cc.log(err);
                return;
            }
            cc.audioEngine.playMusic(item, true); //循环播放, 默认是false(不循环)，背景音乐只存在一个
        });
    }

    playEffect(name, loop = false) {
        cc.loader.loadRes("audio/" + name, cc.AudioClip, (err, item) => {
            if (err) {
                cc.log(err);
                return;
            }
            cc.audioEngine.playEffect(item, loop); //音效可以多个并存
        });
    }
})();
